# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: AlexWMF <alexxwmf@gmail.com>

_realname=liblastfm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.9
pkgrel=3
pkgdesc="A Qt C++ library for the Last.fm webservices https://www.last.fm"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('Boost')
url="https://www.last.fm/download"
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
        "${MINGW_PACKAGE_PREFIX}-fftw"
        "${MINGW_PACKAGE_PREFIX}-libsamplerate")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
options=(!strip staticlibs !buildflags)
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/lastfm/liblastfm/archive/${pkgver}.tar.gz"
        liblastfm-include-suffix.patch::"https://github.com/lastfm/liblastfm/commit/480e2ec6.patch"
        versioned-dlls-mingw.patch)
sha256sums=('5276b5fe00932479ce6fe370ba3213f3ab842d70a7d55e4bead6e26738425f7b'
            'b66614b9508a615e709063074286e7cf6758dd13ab2eea9b2e02897ecba88890'
            '27b2ebcd93744694768051c4b2e0fd5f351337de5d691acccdad53009b5791e5')

prepare() {
    cd ${srcdir}/${_realname}-${pkgver}
    patch -p0 -i ${srcdir}/versioned-dlls-mingw.patch
    patch -p1 -i ../liblastfm-include-suffix.patch # add suffix to Qt5 include dir
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DBUILD_TESTS=False \
    ${srcdir}/${_realname}-${pkgver}

  make ${MAKEFLAGS} # VERBOSE=1
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} -j1 install
}
